//
//  CdModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum CdType: Int {
    case km = 0
    case m = 1
    case dm
    case cm
    case mm
    case um
    case nm
    case pm
    case ly
    case AU
    case inc
    case ft
    case yd
    case mi
    case nmi
    case fm
    case fur
    case mil
    case li
    case zhang
    case chi
    case cun
    case fen
    case lip
    case hao
}


class CdModel: NSObject {
    
    let cdTypes = ["千米","米","分米","厘米","毫米","微米","纳米","皮米","光年","天文单位","英寸","英尺","码","英里","海里","英寻","弗隆","密耳","里","丈","尺","寸","分","厘","毫"]
    let cdSigns = ["km","m","dm","cm","mm","um","nm","pm","ly","AU","in","ft","yd","mi","nmi","fm","fur","mil","","","","","","","","","",""]
    
    
    func kmTm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 1000
        }else{
            h = n * 1000
        }
        return h
    }
    func kmTdm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 10000
        }else{
            h = n * 10000
        }
        return h
    }
    func kmTcm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 100000
        }else{
            h = n * 100000
        }
        return h
    }
    func kmTmm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 1000000
        }else{
            h = n * 1000000
        }
        return h
    }

    func kmTum(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 1000000000
        }else{
            h = n * 1000000000
        }
        return h
    }
    func kmTnm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 1000000000000
        }else{
            h = n * 1000000000000
        }
        return h
    }
    func kmTpm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 1000000000000000
        }else{
            h = n * 1000000000000000
        }
        return h
    }
    
    func kmTly(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 0.000000000000105700083402
        }else{
            h = n * 0.000000000000105700083402
        }
        return h
    }
    
    func kmTAu(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 0.00000000668458712227
        }else{
            h = n * 0.00000000668458712227
        }
        return h
    }
    func kmTin(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 39370.0787402
        }else{
            h = n * 39370.0787402
        }
        return h
    }
    
    func kmTft(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 3280.839895
        }else{
            h = n * 3280.839895
        }
        return h
    }
    func kmTyd(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 1093.6132983
        }else{
            h = n * 1093.6132983
        }
        return h
    }
    func kmTmi(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 0.6213712
        }else{
            h = n * 0.6213712
        }
        return h
    }
    func kmTnmi(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 0.5399568
        }else{
            h = n * 0.5399568
        }
        return h
    }
    func kmTfm(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 546.8066492
        }else{
            h = n * 546.8066492
        }
        return h
    }
    func kmTfur(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 4.9709695
        }else{
            h = n * 4.9709695
        }
        return h
    }
    func kmTmil(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 39370078.74016
        }else{
            h = n * 39370078.74016
        }
        return h
    }
    func kmTli(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 2
        }else{
            h = n * 2
        }
        return h
    }
    func kmTzhang(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 300
        }else{
            h = n * 300
        }
        return h
    }
    func kmTchi(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 3000
        }else{
            h = n * 3000
        }
        return h
    }
    func kmTcun(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 30000
        }else{
            h = n * 30000
        }
        return h
    }
    func kmTfen(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 300000
        }else{
            h = n * 300000
        }
        return h
    }
    func kmTlip(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 3000000
        }else{
            h = n * 3000000
        }
        return h
    }
    func kmThao(n: Double, reverse: Bool = false) -> Double {
        var h: Double = 0
        if reverse {
            h = n / 30000000
        }else{
            h = n * 30000000
        }
        return h
    }
    
    
    func allChange(n: Double, type: CdType) -> [String] {
        var km = n
        switch type {
        case .km:
            break
        case .m:
            km = kmTm(n: n,reverse: true)
            break
        case .dm:
            km = kmTdm(n: n,reverse: true)
            break
        case .cm:
            km = kmTcm(n: n,reverse: true)
            break
        case .mm:
            km = kmTnm(n: n,reverse: true)
            break
        case .um:
            km = kmTum(n: n,reverse: true)
            break
        case .nm:
            km = kmTnm(n: n,reverse: true)
            break
        case .pm:
            km = kmTpm(n: n,reverse: true)
            break
        case .ly:
            km = kmTly(n: n,reverse: true)
            break
        case .AU:
            km = kmTAu(n: n,reverse: true)
            break
        case .inc:
            km = kmTin(n: n,reverse: true)
            break
        case .ft:
            km = kmTft(n: n,reverse: true)
            break
        case .yd:
            km = kmTyd(n: n,reverse: true)
            break
        case .mi:
            km = kmTmi(n: n,reverse: true)
            break
        case .nmi:
            km = kmTnmi(n: n,reverse: true)
            break
        case .fm:
            km = kmTfm(n: n,reverse: true)
            break
        case .fur:
            km = kmTfur(n: n,reverse: true)
            break
        case .mil:
            km = kmTmil(n: n,reverse: true)
            break
        case .li:
            km = kmTli(n: n,reverse: true)
            break
        case .zhang:
            km = kmTzhang(n: n,reverse: true)
            break
        case .chi:
            km = kmTchi(n: n,reverse: true)
            break
        case .cun:
            km = kmTcun(n: n,reverse: true)
            break
        case .fen:
            km = kmTfen(n: n,reverse: true)
            break
        case .lip:
            km = kmTlip(n: n,reverse: true)
            break
        case .hao:
            km = kmThao(n: n,reverse: true)
            break
        }
        return ["\(km)\(cdSigns[0])","\(kmTm(n: km))\(cdSigns[1])","\(kmTdm(n: km))\(cdSigns[2])","\(kmTcm(n: km))\(cdSigns[3])","\(kmTmm(n: km))\(cdSigns[4])","\(kmTum(n: km))\(cdSigns[5])","\(kmTnm(n: km))\(cdSigns[6])","\(kmTpm(n: km))\(cdSigns[7])","\(kmTly(n: km))\(cdSigns[8])","\(kmTAu(n: km))\(cdSigns[9])","\(kmTin(n: km))\(cdSigns[10])","\(kmTft(n: km))\(cdSigns[11])","\(kmTyd(n: km))\(cdSigns[12])","\(kmTmi(n: km))\(cdSigns[13])","\(kmTnmi(n: km))\(cdSigns[14])","\(kmTfm(n: km))\(cdSigns[15])","\(kmTfur(n: km))\(cdSigns[16])","\(kmTmil(n: km))\(cdSigns[17])","\(kmTli(n: km))\(cdSigns[18])","\(kmTzhang(n: km))\(cdSigns[19])","\(kmTchi(n: km))\(cdSigns[20])","\(kmTcun(n: km))\(cdSigns[21])","\(kmTfen(n: km))\(cdSigns[22])","\(kmTlip(n: km))\(cdSigns[23])","\(kmThao(n: km))\(cdSigns[24])"]
    }
    


}

